package com.tsystems.tuni.sportplanet.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlTransient;

/**
 * Player Entity.
 * 
 * @author Yuriy Eremin
 */
@Entity
@Table(name = "player", catalog = "sportsplanet", uniqueConstraints = {
		@UniqueConstraint(columnNames = "name"),
		@UniqueConstraint(columnNames = "email") })
public class Player implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer playerId;
	private Department department;
	private Team team;
	private String name;
	private String email;
	private String phoneNumber;
	private Date birthday;

	public Player() {
	}

	public Player(Department department, Team team, String name, String email,
			String phoneNumber){
		this.department = department;
		this.team = team;
		this.name = name;
		this.email = email;
		this.phoneNumber = phoneNumber;
	}

	public Player(Department department, Team team, String name, String email,
			String phoneNumber,	Date birthday) {
		this.department = department;
		this.team = team;
		this.name = name;
		this.email = email;
		this.phoneNumber = phoneNumber;
		this.birthday = birthday;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "player_id", unique = true, nullable = false)
	public Integer getPlayerId() {
		return this.playerId;
	}

	public void setPlayerId(Integer playerId) {
		this.playerId = playerId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "DEPARTMENT_department_id", nullable = false)
	@XmlTransient
	public Department getDepartment() {
		return this.department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "TEAM_team_id", nullable = false)
	@XmlTransient
	public Team getTeam() {
		return this.team;
	}

	public void setTeam(Team team) {
		this.team = team;
	}

	@Column(name = "name", unique = true, nullable = false, length = 100)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "email", unique = true, nullable = false, length = 45)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@Column(name = "phone_number", nullable = false, length = 10)
	public String getPhoneNumber() {
		return this.phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "birthday", length = 10)
	public Date getBirthday() {
		return this.birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	@Override
	public String toString() {
		return name;
	}

}
